package br.mg.bhe.ftpobre.fs;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Aureliano
 */
public class LocalFileLocalizer implements IFileLocalizer<LocalFile> {

	@Override
	public List<LocalFile> loadFiles(String path) {
		return this.getFiles(path);
	}
	
	private List<LocalFile> getFiles(String path) {
		File seed = new File(path);
		if (!seed.isDirectory()) {
			throw new RuntimeException(seed.getAbsolutePath() + " não é um diretório.");
		}
		
		return this.loadFiles(seed);
	}
	
	private List<LocalFile> loadFiles(File folder) {
		File[] files = folder.listFiles();
		List<LocalFile> localFiles = new ArrayList<LocalFile>();
		
		for (File f : files) {
			if (f.isHidden()) {
				continue;
			}
			
			LocalFile l = new LocalFile();
			
			l.setName(f.getName());
			l.setSize(f.length());
			l.setPath(f.getAbsolutePath());			
			l.setDirectory(f.isDirectory());
			
			localFiles.add(l);
		}
		
		return localFiles;
	}
}